import pyAxios from "./http";

//get

//图片文件上传---MdEditor
export async function upMdEditorImg(filesForm) {
    try {
        const response = await pyAxios({
            method: 'post',
            url: '/file/upImg',
            data: filesForm,
            headers: { "Content-Type": "multipart/form-data" }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//视频文件上传---MdEditor
export async function upMdEditorVideo(filesForm) {
    try {
        const response = await pyAxios({
            method: 'post',
            url: '/file/upVideo',
            data: filesForm,
            headers: { "Content-Type": "multipart/form-data" }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//用户头像上传 包括昵称修改上传
export async function upalterUserInfo(filesForm) {
    console.log("即将提交的表",filesForm);
    try {
        const response = await pyAxios({
            method: 'post',
            url: '/file/alterUserInfo',
            data: filesForm,
            headers: { "Content-Type": "multipart/form-data" }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}


//老师上传资料
export async function upMaterial(filesForm) {
    console.log("即将提交的表",filesForm);
    try {
        const response = await pyAxios({
            method: 'post',
            url: '/file/upMaterials',
            data: filesForm,
            headers: { "Content-Type": "multipart/form-data" }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//老师上传资料
//网页输入http://localhost:8085/file/downloadImg/1.jpg 能下载1.jpg文件
export async function downloadMaterial(fileId) {
    // console.log(fileId);
    
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/file/downloadImg/1.mp4',
        })
        console.log("打印response",response);
        
        return response;
    } catch (error) {
        console.log(error);
    }
}

//管理员新增课程
export async function addCourse(filesForm) {
    try {
        const response = await pyAxios({
            method: 'post',
            url: '/file/addCourse',
            data: filesForm,
            headers: { "Content-Type": "multipart/form-data" }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//老师修改课程列表
export async function alterCourseCover(filesForm) {
    console.log("即将提交的表",filesForm);
    try {
        const response = await pyAxios({
            method: 'post',
            url: '/file/alterCourseCover',
            data: filesForm,
            headers: { "Content-Type": "multipart/form-data" }
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}